import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

const store = new Vuex.Store({
	state: {
		hasLogin: uni.getStorageSync('token') ? true : false,
		userInfo: uni.getStorageSync('userInfo') ? uni.getStorageSync('userInfo') : {}
	},
	mutations: {
		login(state, userInfo) {
			uni.setStorageSync('userInfo', userInfo)
			state.hasLogin = true;
			state.userInfo = userInfo;
		},
		logout(state) {
			uni.setStorageSync('userInfo', {})
			uni.setStorageSync('token', '');
			state.hasLogin = false;
			state.userInfo = {};
		}
	}
})

export default store